import Vue from "vue"
import VueRouter from "vue-router"
import index from "../views/index.vue"
import home from "../views/home.vue"
// 
import zi from "../components/zi.vue"
import fu from "../views/fu.vue"
// 
import list from "../views/list.vue"
import detail from "../views/detail.vue"

import login from "../views/login.vue"

import indexa from "../views/indexa.vue"
import indexb from "../views/indexb.vue"

Vue.use(VueRouter)
const router=new VueRouter({
	// mode: 'history',
	routes:[
		{
			path:"/",
			// redirect:"/home",
			component:index,
			meta:{
				islogin:false
			},
			children: [
				{
					path: 'indexa',
					component: indexa,
				},
				{
					path: 'indexb',
					component: indexb
				}
			],
		},
		{
			path:"/home",
			component:home,
			meta:{
				islogin:false
			},
			children: [
				{
					path: 'indexa',
					component: indexa,
				},
				{
					path: 'indexb',
					component: indexb
				}
			],
		},
		{
			path:"/zi",
			component:zi,
			meta:{
				islogin:false
			}
		},
		{
			path:"/fu",
			component:fu,
			meta:{
				islogin:false
			}
		},
		{	
			path:"/list",
			// path:"/list/:title",
			component:list,
			meta:{
				islogin:true
			}
		},
		{
			path:"/detail",
			component:detail,
			meta:{
				islogin:true
			}
		},
		{
			path:"/login",
			component:login,
			meta:{
				islogin:false
			}
		},
		{
			path:"*",
			component:()=>import("@/views/404"),
			meta:{
				islogin:false
			}
		}
	]
	
})
router.beforeEach((to,from,next)=>{
	let user=JSON.parse(localStorage.getItem("user"))
	if(to.meta.islogin){
		if(user.islogin){
			next()
		}else{
			router.push({
				path:"/login",
				query:{
					url:to.fullPath
				}
			})
		}
	}else{
		next()
	}
})
export default router